import request from '@/utils/request'

// 获取核心指标数据
export function getCoreMetrics() {
  return request({
    url: '/statistics/board/core-metrics',
    method: 'get'
  })
}

// 获取实时监控数据
export function getRealtimeMonitors() {
  return request({
    url: '/statistics/board/realtime-monitors',
    method: 'get'
  })
}

// 获取预警数据
export function getAlertData() {
  return request({
    url: '/statistics/board/alerts',
    method: 'get'
  })
}

// 获取商品分析数据
export function getProductAnalysis() {
  return request({
    url: '/statistics/board/product-analysis',
    method: 'get'
  })
}

// 获取用户分析数据
export function getUserAnalysis() {
  return request({
    url: '/statistics/board/user-analysis',
    method: 'get'
  })
}

// 模拟数据函数
export function getMockCoreMetrics() {
  return Promise.resolve({
    code: 200,
    data: {
      gmv: 1250000,
      gmvGrowth: 0.15,
      orderCount: 3420,
      orderGrowth: 0.08,
      userCount: 15680,
      userGrowth: 0.12,
      avgOrderValue: 365.5,
      avgOrderGrowth: 0.06,
      repurchaseRate: 0.42,
      repurchaseGrowth: 0.03
    }
  })
}

export function getMockRealtimeMonitors() {
  return Promise.resolve({
    code: 200,
    data: {
      onlineUsers: 1245,
      todayOrders: 567,
      todayOrdersGrowth: 0.18,
      todaySales: 89650,
      todaySalesGrowth: 0.22,
      avgResponseTime: 1.2
    }
  })
}

export function getMockAlertData() {
  return Promise.resolve({
    code: 200,
    data: {
      lowStockProducts: [
        { name: '热销T恤-白色-M', stock: 5, threshold: 20 },
        { name: '运动鞋-黑色-42', stock: 3, threshold: 15 },
        { name: '牛仔裤-蓝色-L', stock: 8, threshold: 25 }
      ],
      highRefundOrders: [
        { orderNo: 'ORD20240115001', refundRate: 0.08, amount: 299 },
        { orderNo: 'ORD20240115002', refundRate: 0.12, amount: 458 },
        { orderNo: 'ORD20240115003', refundRate: 0.06, amount: 189 }
      ],
      delayedDeliveries: [
        { orderNo: 'ORD20240114001', delayHours: 52, customer: '张三' },
        { orderNo: 'ORD20240114002', delayHours: 36, customer: '李四' },
        { orderNo: 'ORD20240114003', delayHours: 28, customer: '王五' }
      ]
    }
  })
}

export function getMockProductAnalysis() {
  return Promise.resolve({
    code: 200,
    data: {
      hotProducts: [
        { name: '热销T恤', sales: 1250 },
        { name: '运动鞋', sales: 980 },
        { name: '牛仔裤', sales: 856 },
        { name: '连衣裙', sales: 742 },
        { name: '休闲裤', sales: 698 },
        { name: '卫衣', sales: 634 },
        { name: '短裤', sales: 587 },
        { name: '衬衫', sales: 523 },
        { name: '外套', sales: 456 },
        { name: '裙子', sales: 398 }
      ],
      slowProducts: [
        { name: '冬季大衣', days: 45 },
        { name: '厚毛衣', days: 38 },
        { name: '羽绒服', days: 32 },
        { name: '棉鞋', days: 28 },
        { name: '围巾', days: 25 },
        { name: '手套', days: 22 },
        { name: '帽子', days: 19 },
        { name: '保暖内衣', days: 16 },
        { name: '雪地靴', days: 14 },
        { name: '棉袜', days: 12 }
      ],
      newProducts: [
        { name: '春季新款T恤', sales: 234, conversionRate: 15.6 },
        { name: '时尚运动鞋', sales: 189, conversionRate: 12.3 },
        { name: '休闲牛仔裤', sales: 156, conversionRate: 18.9 },
        { name: '夏季连衣裙', sales: 145, conversionRate: 14.2 },
        { name: '透气运动裤', sales: 123, conversionRate: 16.7 }
      ],
      categoryStructure: [
        { category: '服装', sales: 45.6 },
        { category: '鞋类', sales: 23.4 },
        { category: '配饰', sales: 15.8 },
        { category: '运动', sales: 10.2 },
        { category: '其他', sales: 5.0 }
      ]
    }
  })
}

export function getMockUserAnalysis() {
  return Promise.resolve({
    code: 200,
    data: {
      growthData: {
        dates: ['01-01', '01-02', '01-03', '01-04', '01-05', '01-06', '01-07'],
        values: [1200, 1350, 1280, 1420, 1580, 1650, 1720]
      },
      userSegment: [
        { segment: '新用户', count: 3456 },
        { segment: '活跃用户', count: 8920 },
        { segment: '沉睡用户', count: 2340 }
      ],
      rfmModel: [
        { segment: '重要价值用户', count: 1250 },
        { segment: '重要发展用户', count: 2340 },
        { segment: '重要保持用户', count: 1890 },
        { segment: '重要挽留用户', count: 980 },
        { segment: '一般价值用户', count: 3450 },
        { segment: '一般发展用户', count: 2100 },
        { segment: '一般保持用户', count: 1560 },
        { segment: '一般挽留用户', count: 890 }
      ],
      behaviorPath: [
        { step: '浏览商品', conversionRate: 100 },
        { step: '加入购物车', conversionRate: 35.6 },
        { step: '提交订单', conversionRate: 18.9 },
        { step: '支付完成', conversionRate: 15.2 }
      ]
    }
  })
}